const request = require('superagent')
require('superagent-charset')(request)
const cheerio = require('cheerio')
const async = require('async')

const FS = require('fs');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var startIndex = 2673178;
var endIndex = 2673223;
var count = 0;
const linkArr = []
for (let i = startIndex; i <= endIndex; i++) {
    linkArr.push(`https://m.pomowxw.com/5/5251/${i}.html`)
}
async.mapLimit(linkArr, 50, async function (url) {
    let { text } = await request(url).buffer(true).charset('utf-8'),
        $ = cheerio.load(text),
        content = $('#nr1').html(),
        fileName = $('#nr_title').text().replace(/(.*?)（1 \/ 1）/g,'$1');

    FS.writeFileSync(`./books/${fileName}.txt`, content);
    
    console.log(`章节下载:${++count}`)
}, (err, results) => {

    if (err) throw err

})